﻿///////////////////////////////////////////////////////////////////////////////////////////////////
//------------------------------版权声明----------------------------
//
// 此文件为 SuperMap iObjects .NET 的示范代码
// 版权所有：北京超图软件股份有限公司
//------------------------------------------------------------------
//
//-----------------------SuperMap iObjects .NET 示范程序说明--------------------------
//
//1、范例简介：演示如何实现鹰眼，放大镜功能；
//2、示例数据：安装目录\SampleData\World\World.smwu；
//3、关键类型/成员: 
//      Workspace.Open 方法
//      MapControl.Map 属性
//      Map.Layers 属性 
//      Point2Ds.Add 方法
//      TrackingLayer.Add 方法
//      GeoLine.Style 属性
//        
//4、使用步骤：
//   (1)进行地图操作。
//   (2)选择是否使用放大镜。
//   (3)设置放大镜倍数。
//   (4)左键点击鹰眼图，鹰眼图矩形框移动到鼠标位置，在主视图和放大镜视图中显示内容。
//   (5)在鹰眼视图的矩形框内按住鼠标左键拖动矩形框，在主视图和放大镜视图中显示相应内容。
//---------------------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////////////////////////


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;


namespace SuperMap.SampleCode.Mapping
{
    public partial class FormMain : Form
    {
        private SampleRun m_sampleRun;
        private SuperMap.Data.Workspace m_workspace;
        private SuperMap.UI.MapControl m_mapControlMain;
        private SuperMap.UI.MapControl m_mapControlEagleEyes;
        private SuperMap.UI.MapControl m_mapControlMagnifier;
        /// <summary>
        /// 初始化窗体
        /// </summary>
        public FormMain()
        {
            try
            {
                InitializeComponent();

                m_workspace = new SuperMap.Data.Workspace(this.components);

                m_mapControlMain = new SuperMap.UI.MapControl();
                m_mapControlMain.Dock = DockStyle.Fill;
                m_panelMapcontrol.Controls.Add(m_mapControlMain);

                m_mapControlEagleEyes = new SuperMap.UI.MapControl();
                m_mapControlEagleEyes.Dock = DockStyle.Fill;
                m_panelEagleEyeMap.Controls.Add(m_mapControlEagleEyes);

                m_mapControlMagnifier = new SuperMap.UI.MapControl();
                m_mapControlMagnifier.Dock = DockStyle.Fill;
                m_panelMagnifier.Controls.Add(m_mapControlMagnifier);

                //实例化SampleRun
                m_sampleRun = new SampleRun(m_workspace, m_mapControlMain, m_mapControlEagleEyes, m_mapControlMagnifier);

                m_checkboxMagnifier.Checked = true;
                m_comboBoxScale.SelectedItem = m_comboBoxScale.Items[2];
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
        }


        /// <summary>
        /// 在窗体关闭时，需要释放相关的资源
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void FormMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            try
            {
                m_mapControlMain.Dispose();
                m_mapControlEagleEyes.Dispose();
                m_mapControlMagnifier.Dispose();
                m_workspace.Dispose();
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
        }

        /// <summary>
        /// 判断是否显示专题图
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void m_checkboxMagnifier_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                if (m_checkboxMagnifier.Checked == false)
                {
                    m_label.Enabled = false;
                    m_comboBoxScale.Enabled = false;
                    m_sampleRun.IsUseMagnifierChecked = false;
                }
                else
                {
                    m_label.Enabled = true;
                    m_comboBoxScale.Enabled = true;
                    m_sampleRun.IsUseMagnifierChecked = true;
                }

                m_sampleRun.ZoomForView(m_comboBoxScale.SelectedIndex);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
        }

        /// <summary>
        /// 用于控制放大的倍数，调用ZoomForView()，进行放大显示
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void m_comboBoxScale_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                Int32 index = m_comboBoxScale.SelectedIndex;
                m_sampleRun.ZoomForView(index);
                m_sampleRun.SelectScaleIndex = index;
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
        }

        private void m_panelEagleEyeMap_Paint(object sender, PaintEventArgs e)
        {

        }
    }
}

